import { _decorator, Component, Node, ITriggerEvent, Prefab, Vec3, BoxColliderComponent, CCFloat } from 'cc';
import { constant } from '../../constant';
import { GameApp } from '../../GameApp';

import { enemyBase } from '../enemyBase';




//所有爆炸类的技能
const { ccclass, property } = _decorator;

@ccclass('towerFire')
export class towerFire extends Component {

    @property({ type: CCFloat, displayName: "伤害" })
    private hitNum: number = 0.5;








    private howHit: Node = null






    private _colliderCom: BoxColliderComponent = null!;//




    onLoad() {


        this._colliderCom = this.node.getComponent(BoxColliderComponent)
        this.hitNum += GameApp.Instance.level * this.hitNum * constant.towerAttack
    }

    init(howHit: Node) {
        this.howHit = howHit
        console.log("火焰howHit");

    }
    onEnable() {


        this._colliderCom.on("onTriggerStay", this._onTriggerEnterCb, this);




    }



    onDisable() {

    }


    onDestroy() {

        this._colliderCom.off("onTriggerStay", this._onTriggerEnterCb, this);




    }

    private _onTriggerEnterCb(event: ITriggerEvent) {




        const other: Node = event.otherCollider.node

        console.log("碰到的敌人", other);

        const ts: enemyBase = other.getComponent(enemyBase)
        if (ts) {
            console.log("有ts");

            ts.hit(this.hitNum, this.howHit)


        }






    }
    update(dt: number) {


    }
}

